﻿using Microsoft.VisualStudio.TestTools.UnitTesting;


namespace MinesweeperModel.Test
{
    [TestClass]
    public class MinesweeperTest
    {
        private int BombCount(Cell[,] cells)
        {
            int t = 0;
            foreach (var cell in cells)
            {
                t += (cell.NeighborBombCount == Cell.BOMB ? 1 : 0);
            }
            return t;
        }
        private int ExposedCount(Cell[,] cells)
        {
            int t = 0;
            foreach (var cell in cells)
            {
                t += (cell.isExposed ? 1 : 0);
            }
            return t;
        }

        [TestMethod]
        public void CtorTest()
        {
            // Arrange
            var ms = new Minesweeper();
            // Act
            //ms.Init();
            // Assert
            var actualBombs = BombCount(ms.Grid);
            Assert.AreEqual(10, actualBombs);
        }


        [TestMethod]
        public void ExposeTest_0Mines()
        {
            // Arrange
            var ms = new Minesweeper(10, 10, 0);
            // Act
            ms.Expose(0, 0);
            // Assert
            foreach (var cell in ms.Grid)
                Assert.IsTrue(cell.isExposed);
        }

        [TestMethod]
        public void ExposeTest_1Mines()
        {
            // Arrange
            var ms = new Minesweeper(10, 10, 1);
            // Act
            ms.Expose(4, 6);
            // Assert
            Assert.AreEqual(99, ExposedCount(ms.Grid));
        }
    }
}
